Skip to content

Add values(start, end) slice accessor to DoubleEndedQueue#6522

Open
ernestognw wants to merge 2 commits into
OpenZeppelin:masterfrom
ernestognw:feat/deque-values-slice
Open

Add values(start, end) slice accessor to DoubleEndedQueue#6522
ernestognw wants to merge 2 commits into
OpenZeppelin:masterfrom
ernestognw:feat/deque-values-slice

Conversation

@ernestognw
Copy link
Copy Markdown
Member

Summary

  • Adds values(Bytes32Deque storage deque, uint256 start, uint256 end) to DoubleEndedQueue, mirroring the paginated values accessor in EnumerableSet.
  • end is clamped to length(deque) and start is clamped to the (clamped) end via Math.min, so any out-of-range inputs return a properly bounded slice instead of reverting.
  • The slice reads through deque._data[_begin + i], so it honors the wraparound indices used by pushFront/popFront.

Test plan

  • npx hardhat test test/utils/structs/DoubleEndedQueue.test.js — 22 cases passing (16 pre-existing + 6 new under values: empty deque, full-range, exhaustive [0..4] x [0..4] pagination, MaxUint256 end clamping, start > end / start > length clamping, and a wraparound case that exercises the _begin - 1 underflow path via pushFront).

Mirrors the paginated `values` accessor in `EnumerableSet`. Clamps `end` to
`length(deque)` and `start` to `end` (both with `Math.min`), then reads the
slice through the wraparound-aware `_begin` offset.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ernestognw ernestognw requested a review from a team as a code owner May 15, 2026 21:38
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 15, 2026

🦋 Changeset detected

Latest commit: 508c781

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
openzeppelin-solidity Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 15, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b725917b-d5d6-40b3-859e-34dfa2c083c5

📥 Commits

Reviewing files that changed from the base of the PR and between cd05883 and be5c60a.

📒 Files selected for processing (3)
  • .changeset/noisy-dragons-paint.md
  • contracts/utils/structs/DoubleEndedQueue.sol
  • test/utils/structs/DoubleEndedQueue.test.js

Walkthrough

This PR adds a new values(deque, start, end) internal view function to DoubleEndedQueue that returns a paginated slice of the deque as a memory array. The implementation imports Math for clamping logic and copies the selected storage elements into memory while handling out-of-range bounds. Comprehensive test coverage validates full-range returns, pagination across multiple begin/end pairs, proper clamping behavior, and correct element ordering including wraparound scenarios. The changeset documents the feature as a minor release update.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: adding a new slice accessor function to DoubleEndedQueue.
Description check ✅ Passed The description is directly related to the changeset, providing technical details about the implementation, design choices, and comprehensive test coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@ernestognw ernestognw added this to the 5.7 milestone May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants